<?php
#
# author: Phil Spagnolo and Cody Sorgenfrey
# (c)2008 South Hill Calvary Chapel
#
include_once("./common.php");
include_once("./mysql/common.php");
include_once("./mysql/database_info.php");
$title = "Resources";
$meta_key='admin, administration, handbook, finances, forms, organization, discipleship, directory';
$meta_desc="The resource pool for South Hill Calvary Chapel.";
print_html_head($title ,$meta_key,$meta_desc);
print_java_head(NULL);
begin_body();
page_title($title);
connect_select_test("resources");
function printBlock($title)
{
	$result = mysql_fetch_array(mysql_query("SELECT * FROM `resources` WHERE `name`='$title'"));
	$titles = explode("\n", $result['titles']);
	$links = explode("\n", $result['links']);
	$description = $result['description'];
	printf("<h4>%s</h4>\n", $title);
	printf("<p>%s</p>\n", $description);
	printf("<ul>\n");
	for ($x=0;$x<count($titles);$x++){
		$titles2 = explode(",", $titles[$x]);
		$links2 = explode(",", $links[$x]);
		printf("\t<li>\n");
		printf("\t\t<a href='%s' target='_blank'>\n", $links2[0]);
		printf("\t\t\t%s\n", $titles2[0]);
		printf("\t\t</a>\n");
		if (count($titles2) > 1){
			printf("\t\t<ol>\n");
			for($y=1;$y<count($titles2);$y++){
				printf("\t\t\t<li>\n");
				if (!empty($links2[$y])){
					printf("\t\t\t\t<a href='%s' target='_blank'>\n", $links2[$y]);
					printf("\t\t\t\t\t%s\n", $titles2[$y]);
					printf("\t\t\t\t</a>\n");
				} else {
					printf("\t\t\t\t%s\n", $titles2[$y]);
				}
				printf("\t\t\t</li>\n");
			}
			printf("\t\t</ol>\n");
		}
		printf("\t</li>\n");
	}
	printf("</ul>\n");
}
$greeting = mysql_fetch_array(mysql_query("SELECT * FROM `resources` WHERE `name`='Greeting'"));
printf("<p>%s</p>\n", $greeting['description']);
$pageResult = mysql_query("SELECT * FROM `resources` WHERE `name`!='Greeting' ORDER BY `name` ASC");
while ($pageContent = mysql_fetch_array($pageResult)){
	printBlock($pageContent['name']);
}
end_body();
?>
